export interface GetWechatBindPhoneParams {
  code: string;
}

export interface GetWechatBindPhoneResponse {
  phone: string;
  uid: string;
}

/**
 * @description 微信小程序登录参数
 * @interface MPWechatLoginParams
 * @property {string} code - uni.login 获取的code
 * @property {string} nickname - 用户昵称
 * @property {string} avatar - 用户头像
 */
export interface MPWechatLoginParams {
  code: string;
  nickname: string;
  avatar: string;
}

/**
 * @description 微信小程序登录返回的令牌信息
 * @interface MPWechatLoginResponseToken
 * @property {string} access_token - 访问令牌
 * @property {string} refresh_token - 刷新令牌
 * @property {number} expire - 令牌过期时间
 *
 */
export interface MPWechatLoginResponseToken {
  access_token: string;
  refresh_token: string;
  expire: number;
}

/**
 * @description 微信小程序登录返回的用户信息
 * @interface UserInfo
 * @property {number} id - 用户ID
 * @property {string} name - Odoo用户昵称
 * @property {string} avatar_url - 用户头像URL
 * @property {string} nickname - 微信用户昵称
 * @property {string | null} phone - 手机号码
 *
 */
export interface UserInfo {
  id: number;
  name: string;
  avatar_url: string;
  nickname: string;
  phone: string | null;
}

/**
 * @description 微信小程序登录响应
 * @interface MPWechatLoginResponse
 * @property {string} session_id - 会话ID
 * @property {string} code - 登录返回的code
 * @property {MPWechatLoginResponseToken} token - 登录令牌信息
 * @property {UserInfo} user - 登录用户信息
 */
export interface MPWechatLoginResponse {
  session_id: string;
  code: string;
  token: MPWechatLoginResponseToken;
  user: UserInfo;
}

export interface MPWechatLoginResponse {
  id: number;
}
// 获取微信绑定手机号
export function getPhoneNumber(params: GetWechatBindPhoneParams) {
  return uni.$u.http.post<GetWechatBindPhoneResponse>(
    "/wechat_mini/phone/code/no",
    params
  );
}

// 微信小程序登录接口
export function mpWechatLogin(params: MPWechatLoginParams) {
  return uni.$u.http.post<MPWechatLoginResponse>(
    "/login/oauth2/wechat_mini/code",
    params
  );
}
